﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.Organizations{
	public partial class OrganizationsInputFields : SERP.Modules.ModuleBase
	{
		protected void Page_Load(object sender, EventArgs e){
			LoadLanguage();
		}
		private OrganizationsEntity model=new OrganizationsEntity();
		public OrganizationsEntity Model{
			set{
				model=value;
			}
			get{
				return model;
			}
		}
		//Load All lable text
		private void LoadLanguage(){
			labelOrgCode.Text=OrganizationsStringMapping.OrgCode+":";
			labelOrgName.Text=OrganizationsStringMapping.OrgName+":";
			labelNote.Text=OrganizationsStringMapping.Note+":";
			labelOrgType.Text=OrganizationsStringMapping.OrgType+":";
			validRQOrgType.ErrorMessage=SERP.Constants.APP_REQUIRE_WARNING;	
			validExpressionOrgType.ErrorMessage=SERP.Constants.APP_REQUIRE_INTERGER_WARNING;
			labelParentId.Text=OrganizationsStringMapping.ParentId+":";
			validRQParentId.ErrorMessage=SERP.Constants.APP_REQUIRE_WARNING;
		}   
		public void UpdateToModel(){
			model.OrgCode=Convert.ToString(txtOrgCode.Text);
			model.OrgName=Convert.ToString(txtOrgName.Text);
			model.Note=Convert.ToString(txtNote.Text);
			model.OrgType=Convert.ToByte(txtOrgType.Text);
			model.ParentId=Convert.ToInt32(txtParentId.SelectedValue);
		}
		public void UpdateToScreen(){
			txtOrgCode.Text=model.OrgCode;
			txtOrgName.Text=model.OrgName;
			txtNote.Text=model.Note;
			txtOrgType.Text=Convert.ToString(model.OrgType);
			txtParentId.SelectedValue=model.ParentId.ToString();
		}
		public void ClearScreen(){
			txtOrgCode.Text="";
			txtOrgName.Text="";
			txtNote.Text="";
			txtOrgType.Text="0";
		}
		public bool ValidateScreen(){
			bool result=true;
			if(txtParentId.SelectedIndex<=0){
				result=false;
				validRQParentId.IsValid=false;
			}
			else{
				validRQParentId.IsValid=true;
			}
			return result;
		}	
	}
}
